package com.itheima.springbootinit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Hello {

    //获取对象属性
    @Value("${person.name}")
    private String name;
    @Value("${person1.name}")
    private String name1;

    //获取数组属性
    @Value("${address[0]}")
    private String add;
    @Value("${address1[1]}")
    private String add1;

    //获取纯量
    @Value("${msg1}")
    private String msg1;
    @Value("${msg2}")
    private String msg2;

    //引用值
    @Value("${user.name}")
    private String user;


    @Autowired
    private Environment env;

    @Autowired
    private Person person;


    @RequestMapping("/you")
    public String How2() {
        System.out.println(name);
        System.out.println(name1);
        System.out.println(add);
        System.out.println(add1);
        System.out.println(msg1);
        System.out.println(msg2);
        System.out.println(user);
        System.out.println("-----------------------");


        System.out.println(env.getProperty("person.name"));
        System.out.println(env.getProperty("address1[1]"));
        System.out.println("-----------------------");


        System.out.println(person);
        String[] add = person.getAdd();
        for (String s : add) {
            System.out.println(s);
        }
        return "how are you";
    }


    @RequestMapping("/how")
    public String How() {
        return "how are you";
    }
}
